﻿var UserManage = {
    Delete: function () {
        var ids = $("input[name='uids']").getCheckBoxValue().toString();
        if (ids == null || ids == undefined || ids == "") {
            alertMsg.info('请选择要删除的用户！');
            return false;
        }
        alertMsg.confirm('确定要删除勾选的用户吗？', { okCall: function () {
            $.ajax({
                url: "Manage/User/Delete",
                data: { 'ids': ids },
                dataType: 'json',
                success: function (data) {
                    if (data.statusCode == DWZ.statusCode.ok) {
                        alertMsg.correct(data.message);
                        navTab.openTab(data.navTabId, data.forwardUrl, { title: data.title, fresh: true });
                    }
                }
            });
        }
        });
    },
    SaveUser: function (obj, callbackfn) {
        var name = $(obj).find("input[name='name']").val();
        if (!name) {
            alertMsg.error("请填写用户姓名！");
            return false;
        }
        var login_name = $(obj).find("input[name='login_name']").val();
        if (!login_name) {
            alertMsg.error("请填写登录名！");
            return false;
        }
        var role = $(obj).find("select[name='role']").val();
        if (!role) {
            alertMsg.error("请选择角色！");
            return false;
        }
        if (confirm("确定要保存用户吗？")) {
            return validateCallback(obj, callbackfn);
        }
        else {
            return false;
        }

    },
    SavePwd: function (obj, callbackfn) {
        var opwd = $(obj).find("input[name='opwd']").val();
        if (!opwd) {
            alertMsg.error("请填写旧密码！");
            return false;
        }
        var pwd1 = $(obj).find("input[name='pwd1']").val();
        if (!pwd1) {
            alertMsg.error("请填写新密码！");
            return false;
        }
        var pwd2 = $(obj).find("input[name='pwd2']").val();
        if (!pwd2) {
            alertMsg.error("请填写确认新密码！");
            return false;
        }
        if (pwd1 != pwd2) {
            alertMsg.error("密码不一致！");
            return false;
        }
        if (confirm("确定要保存密码吗？")) {
            return validateCallback(obj, callbackfn);
        }
        else {
            return false;
        }
    },
    dialogAjaxDone: function (data) {
        if (data.statusCode == DWZ.statusCode.ok) {
            $.pdialog.closeCurrent();
            navTab.openTab(data.navTabId, data.forwardUrl, { title: data.title, fresh: true });
            setTimeout(function () {
                alertMsg.correct(data.message);
            }, 500);

        }
        else if (data.statusCode == DWZ.statusCode.error) {
            alertMsg.error(data.message);
        }
    }
}